//
//  CJViewController.m
//  抽奖页面
//
//  Created by iOS程序员 on 15/12/3.
//  Copyright © 2015年 iOS程序员. All rights reserved.
//

#import "CJViewController.h"
#import "Hong.pch"
#import "PTView.h"
@interface CJViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong)UIImageView *titleView;//标题图
@property (nonatomic,strong)UIImageView *act1View;//活动1
@property (nonatomic,strong)UILabel *act1Lb;//活动1文字
@property (nonatomic,strong)UILabel *act1Lbt;//活动1内容
@property (nonatomic,strong)LKLotteryView *lotteryView;//中奖轮盘1
@property (nonatomic,strong)UIImageView *name;//中奖名单
@property (nonatomic,strong)ROllLabel *rolabel;//滚动中奖名单
@property (nonatomic,strong)UIImageView *actshuoming;//活动说明
@property (nonatomic,strong)UILabel *cjshuoming;//抽象说明
@property (nonatomic,strong)UIImageView *prizeint;//奖品介绍
@property (nonatomic,strong)UILabel *prizeshuoming;//奖品说明
@property (nonatomic,strong)UILabel *act2Lb;//活动1文字
@property (nonatomic,strong)UILabel *act2Lbt;//活动1内容
@property (nonatomic,strong)LKLotteryView *lotteryView2;//中奖轮盘2
@property (nonatomic,strong)UITableView *listTable;//中奖名单
@property (nonatomic,strong)NSMutableArray *arr;
@property (nonatomic,strong)UILabel *styleLabel;//抽奖方式说明
@end

@implementation CJViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    UIScrollView *cjScroller = [[UIScrollView alloc]initWithFrame:self.view.frame];
    [self.view addSubview:cjScroller];
    cjScroller.contentSize = CGSizeMake(0, 3000*HEIGH);
    cjScroller.contentOffset = CGPointMake(0, 0);
    cjScroller.scrollsToTop = YES;
    cjScroller.bounces  = NO;
    cjScroller.showsVerticalScrollIndicator = NO;
    
    self.titleView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, W, 250 * HEIGH)];
    self.titleView.image = [UIImage imageNamed:@"cj1.jpg"];
    [cjScroller addSubview:_titleView];
    
    self.act1View = [[UIImageView alloc]initWithFrame:CGRectMake(0, 250 * HEIGH , W, 150*HEIGH)];
    self.act1View.image = [UIImage imageNamed:@"cj2.jpg"];
    [cjScroller addSubview:_act1View];
    
    self.act1Lb  = [[UILabel alloc]initWithFrame:CGRectMake(12*WIDTH, 15*HEIGH, 50*WIDTH, 25*HEIGH)];
    self.act1Lb.text = @"活动一";
    self.act1Lb.textColor = [UIColor whiteColor];
    self.act1Lb.font = [UIFont systemFontOfSize:14*WIDTH];
    [self.act1View addSubview:_act1Lb];
    
    self.act1Lbt = [[UILabel alloc]initWithFrame:CGRectMake(12*WIDTH, 40*HEIGH, 150*WIDTH, 40*HEIGH)];
    self.act1Lbt.text = @"注册会员抽大奖";
    self.act1Lbt.textColor = [UIColor whiteColor];
    self.act1Lbt.font = [UIFont systemFontOfSize:25*WIDTH];
    [self.act1View addSubview:_act1Lbt];
    
    self.lotteryView  = [[LKLotteryView alloc]initWithFrame:CGRectMake(0, 400 * WIDTH, W,340 *WIDTH)];
    [cjScroller addSubview:_lotteryView];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
    btn.backgroundColor = [UIColor blueColor];
    btn.frame = CGRectMake(0, 0, 50* WIDTH, 50*HEIGH);
    btn.center = self.lotteryView.center;
    btn.backgroundColor = [UIColor clearColor];
    [btn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [cjScroller addSubview:btn];
    
    [self.lotteryView setDialPanel:[UIImage imageNamed:@"cj4.png"] pointer:[UIImage imageNamed:@"cj3.jpg"]];
    self.name = [[UIImageView alloc]initWithFrame:CGRectMake(0, 740* WIDTH, W, 50*WIDTH)];
    self.name.image = [UIImage imageNamed:@"cj5.jpg"];
    [cjScroller addSubview:_name];
    
    self.rolabel = [[ROllLabel alloc] initWithFrame:CGRectMake(100*WIDTH    , 25*HEIGH, 220*WIDTH, 20*HEIGH) withBgColor:[UIColor clearColor]];
    [self.rolabel setTimeInterval:4.0f];
    [self.rolabel setAnimationOption:UIViewAnimationOptionCurveLinear];
    [self.rolabel rollOnlyOneTitle:@"XXXXX真是太幸运了，恭喜获得三等奖" textcolor:[UIColor redColor] font:[UIFont systemFontOfSize:14*WIDTH]];
    [self.name addSubview:_rolabel];
    
    self.actshuoming = [[UIImageView alloc]initWithFrame:CGRectMake(0, 790*HEIGH, W, 50*HEIGH)];
    self.actshuoming.image = [UIImage imageNamed:@"cj7.jpg"];
    [cjScroller addSubview:_actshuoming];
    
    UIView * view = [[UIView alloc]init];
    view.backgroundColor = [UIColor colorWithRed:232 /255.0 green:32/255.0 blue:77/255.0 alpha:1];
    [cjScroller addSubview:view];
    
    self.cjshuoming = [[UILabel alloc]initWithFrame:CGRectMake(10*WIDTH, 12*HEIGH, 355*WIDTH, 100*HEIGH)];
    self.cjshuoming.text = @"打碎扫活动；大赛挥洒 回复都是佛；DSA搜；的说法iof沙发时代封ID施工方的都是爸爸合法士大夫撒 说法萨芬佛萨博 方式舒服撒衣服撒股份公司的风格撒发生改善皮肤干啥地方沙发萨丹哈 放大搜狐偏大还是感觉受到撒回家活动三从地上";
    self.cjshuoming.backgroundColor = [UIColor yellowColor];
    self.cjshuoming.textColor = [UIColor blackColor];
    self.cjshuoming.font = [UIFont systemFontOfSize:14*WIDTH];
    [view addSubview:_cjshuoming];
    CGRect rect = [self.cjshuoming.text boundingRectWithSize:CGSizeMake(355*WIDTH, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:self.cjshuoming.font} context:nil];
    self.cjshuoming.numberOfLines = 0;
    self.cjshuoming.frame = CGRectMake(self.cjshuoming.frame.origin.x, self.cjshuoming.frame.origin.y, rect.size.width, rect.size.height+ 20*HEIGH);
    view.frame = CGRectMake(0, 840*WIDTH, W, self.cjshuoming.frame.size.height+24*HEIGH);
    self.cjshuoming.layer.cornerRadius = 4;
    self.cjshuoming.layer.masksToBounds = YES;
    
    self.prizeint = [[UIImageView alloc]initWithFrame:CGRectMake(0, 840*HEIGH + view.frame.size.height, W, 50*HEIGH)];
    self.prizeint.image  = [UIImage imageNamed:@"cj8.jpg"];
    [cjScroller addSubview:_prizeint];
    
    UIView *view1 = [[UIView alloc]init];
    view1.backgroundColor = [UIColor colorWithRed:237 /255.0 green:26/255.0 blue:73/255.0 alpha:1];
    [cjScroller addSubview:view1];
    
    self.prizeshuoming = [[UILabel alloc]initWithFrame:CGRectMake(10*WIDTH, 12*HEIGH, 355*WIDTH, 100*HEIGH)];
    self.prizeshuoming.text = @"大声的撒的撒电脑第三i大撒把的撒 牌舍得你到底吧安地方吧大师傅封IDASF那是平南方都是南方飞洒fdsan0哪怕农行烦死你  能否佛山呢 哦 ";
    self.prizeshuoming.backgroundColor = [UIColor clearColor];
    self.prizeshuoming.textColor = [UIColor whiteColor];
    self.prizeshuoming.font = [UIFont systemFontOfSize:14*WIDTH];
    [view1 addSubview:_prizeshuoming];
    CGRect rect2 = [self.prizeshuoming.text boundingRectWithSize:CGSizeMake(355*WIDTH, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:self.prizeshuoming.font} context:nil];
    self.prizeshuoming.numberOfLines = 0;
    self.prizeshuoming.frame = CGRectMake(self.prizeshuoming.frame.origin.x, self.prizeshuoming.frame.origin.y, rect2.size.width, rect2.size.height+ 20*HEIGH);
    
    int numberPerLine = 3;// 每行显示多少个view
    int numberOfLine = 2;// 一共多少行
    
    // 总共循环的次数就是 行数* 每行的个数
    for(int i = 0; i < numberPerLine * numberOfLine; i++)
    {
        // 计算每个view的frame
        CGRect frame = CGRectMake(20*WIDTH + i % numberPerLine * 115 * WIDTH,self.prizeshuoming.frame.size.height + 12 * HEIGH+ i / numberPerLine * 130 * HEIGH,100*WIDTH, 120*HEIGH);
        
        PTView *ptView = [[PTView alloc] initWithFrame:frame];
        ptView.myLabel.text = @"乐扣三件套17元\n（共200名）";
        ptView.myView.image = [UIImage imageNamed:@"cj9.jpg"];
        [view1 addSubview:ptView];

    }
    view1.frame = CGRectMake(0, 890*HEIGH+view.frame.size.height, W, self.prizeshuoming.frame.size.height+262*HEIGH);
    UIImageView *act2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 890*HEIGH+view1.frame.size.height+view.frame.size.height ,W, 150*HEIGH)];
    act2.image = [UIImage imageNamed:@"cj11.jpg"];
    [cjScroller addSubview:act2];
    self.act2Lb  = [[UILabel alloc]initWithFrame:CGRectMake(310*WIDTH, 25*HEIGH, 50*WIDTH, 25*HEIGH)];
    self.act2Lb.text = @"活动二";
    self.act2Lb.textColor = [UIColor whiteColor];
    self.act2Lb.font = [UIFont systemFontOfSize:14*WIDTH];
    [act2 addSubview:_act2Lb];
    
    self.act2Lbt = [[UILabel alloc]initWithFrame:CGRectMake(230*WIDTH, 50*HEIGH, 150*WIDTH, 40*HEIGH)];
    self.act2Lbt.text = @"购物抽大奖";
    self.act2Lbt.textColor = [UIColor whiteColor];
    self.act2Lbt.font = [UIFont systemFontOfSize:25*WIDTH];
    [act2 addSubview:_act2Lbt];
    
    self.lotteryView2  = [[LKLotteryView alloc]initWithFrame:CGRectMake(0, 1040* WIDTH +view.frame.size.height+view1.frame.size.height, W,340 *WIDTH)];
    [cjScroller addSubview:_lotteryView2];
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeSystem];
    btn2.backgroundColor = [UIColor blueColor];
    btn2.frame = CGRectMake(0, 0, 50* WIDTH, 50*HEIGH);
    btn2.center = self.lotteryView2.center;
    NSLog(@"%f %f",self.lotteryView2.frame.origin.x,self.lotteryView2.frame.size.width);
    btn2.backgroundColor = [UIColor clearColor];
    [btn2 addTarget:self action:@selector(buttonAction2:) forControlEvents:UIControlEventTouchUpInside];
    [cjScroller addSubview:btn2];
    
    [self.lotteryView2 setDialPanel:[UIImage imageNamed:@"cj4"] pointer:[UIImage imageNamed:@"cj20"]];
    
    UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(0, 1380*HEIGH+view.frame.size.height+view1.frame.size.height, W, 70*HEIGH)];
    view3.backgroundColor = RGBACOLOR(240, 240, 240, 1);
    [cjScroller addSubview:view3];
    
    UIImageView *list = [[UIImageView alloc]initWithFrame:CGRectMake(0, 1430*HEIGH+view.frame.size.height+view1.frame.size.height, W, 35*HEIGH)];
    list.image  = [UIImage imageNamed:@"cj14.jpg"];
    [cjScroller addSubview:list];
    UIImageView *listName = [[UIImageView alloc]initWithFrame:CGRectMake(0, 1465*HEIGH+view.frame.size.height+view1.frame.size.height, W, 180*HEIGH)];
    listName.image = [UIImage imageNamed:@"cj10.jpg"];
    [cjScroller addSubview:listName];
    self.listTable = [[UITableView alloc]initWithFrame:CGRectMake(80*WIDTH, 35*HEIGH, 220*WIDTH, 110*HEIGH) style:UITableViewStylePlain];
    self.listTable.separatorStyle = NO;
    self.listTable.backgroundColor = [UIColor clearColor];
    self.listTable.delegate = self;
    self.listTable.dataSource = self;
    self.listTable.rowHeight = 28*HEIGH;
    [listName addSubview:_listTable];
    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES];
    self.arr = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",nil];
    UIView *explainView = [[UIView alloc]init];
    explainView.backgroundColor = RGBACOLOR(240, 240, 240, 1);
    self.styleLabel = [[UILabel alloc]initWithFrame:CGRectMake(30*WIDTH, 12*HEIGH, 285*WIDTH, 100*HEIGH)];
    self.styleLabel.text = @"大声的撒的撒电脑第三i大撒把的撒 牌舍得你到底吧安地方吧大师傅封IDASF那是平南方都是南方飞洒fdsan0哪怕农行烦死你  能否佛山呢 哦 ";
    self.styleLabel.textColor = RGBACOLOR(218, 87, 113, 1);
    self.styleLabel.font = [UIFont systemFontOfSize:14*WIDTH];
    [explainView addSubview:self.styleLabel];
    CGRect rect3 = [self.styleLabel.text boundingRectWithSize:CGSizeMake(315*WIDTH, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:self.styleLabel.font} context:nil];
    self.styleLabel.numberOfLines = 0;
    self.styleLabel.frame = CGRectMake(self.styleLabel.frame.origin.x, self.styleLabel.frame.origin.y, rect3.size.width, rect3.size.height+ 20*HEIGH);
    explainView.frame = CGRectMake(0, 1645*WIDTH+view.frame.size.height+view1.frame.size.height, W, self.styleLabel.frame.size.height+24*HEIGH);
    [cjScroller addSubview:explainView];
    UIImageView *viewQin = [[UIImageView alloc]initWithFrame:CGRectMake(0, 1645*HEIGH+view.frame.size.height+view1.frame.size.height+explainView.frame.size.height, W, 230*HEIGH)];
    viewQin.image = [UIImage imageNamed:@"cj15.jpg"];
    [cjScroller addSubview:viewQin];
    
    UIView *view4 = [[UIView alloc]initWithFrame:CGRectMake(0, 1875*HEIGH+view.frame.size.height+view1.frame.size.height+explainView.frame.size.height, W, 220*HEIGH)];
    view4.backgroundColor = RGBACOLOR(255, 254, 84, 1);
    // 总共循环的次数就是 行数* 每行的个数
    for(int j = 0; j < numberPerLine * numberOfLine; j++)
    {
        // 计算每个view的frame
        CGRect frame = CGRectMake( j % numberPerLine * 125 * WIDTH,j / numberPerLine * 100 * HEIGH,125*WIDTH, 100*HEIGH);
        
        PTView *ptView = [[PTView alloc] initWithFrame:frame];
        ptView.myLabel.backgroundColor = RGBACOLOR(255, 254, 84, 1);
        ptView.myLabel.text = @"返现奖100元\n（若干名）";
        ptView.myLabel.textColor = [UIColor blackColor];
        ptView.myLabel.font = [UIFont systemFontOfSize:11*WIDTH];
        ptView.myView.image = [UIImage imageNamed:@"cj16.jpg"];
        [view4 addSubview:ptView];
        
    }
    [cjScroller addSubview:view4];
    UIView *view5 = [[UIView alloc]initWithFrame:CGRectMake(0, 2095*HEIGH+view.frame.size.height+view1.frame.size.height+explainView.frame.size.height,W , 60*HEIGH)];
    view5.backgroundColor = RGBACOLOR(226, 46, 81, 1);
    UILabel *labelJ = [[UILabel alloc]initWithFrame:CGRectMake(0, 0,240*WIDTH , 40*HEIGH)];
    labelJ.center = view5.center;
    labelJ.text = @"温馨提示：最终解释权归中皮网所属";
    labelJ.font = [UIFont systemFontOfSize:13*WIDTH];
    labelJ.textAlignment = NSTextAlignmentCenter;
    labelJ.textColor = [UIColor whiteColor];
    [cjScroller addSubview:view5];
    [cjScroller addSubview:labelJ];
    
    cjScroller.contentSize =CGSizeMake(0,2219*HEIGH+view.frame.size.height+view1.frame.size.height+explainView.frame.size.height);
}

- (void)buttonAction:(UIButton *)btn
{
    [self.lotteryView start];
}
- (void)buttonAction2:(UIButton *)btn
{
    [self.lotteryView2 start];
}

- (void)timerAction:(NSTimer *)timer
{
    if (self.listTable.contentOffset.y < self.listTable.rowHeight*self.arr.count) {
        [self.listTable setContentOffset:CGPointMake(0, self.listTable.contentOffset.y + self.listTable.rowHeight) animated:YES];
    }else if (self.listTable.contentOffset.y >= self.listTable.rowHeight*self.arr.count){
        self.listTable.contentOffset = CGPointMake(0, 0);
        [self.listTable setContentOffset:CGPointMake(0, self.listTable.contentOffset.y + self.listTable.rowHeight) animated:YES];

    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
    return self.arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    
    static NSString *str = @"suibian";
    UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:str];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:str];
    }
    
    cell.textLabel.text = [self.arr objectAtIndex:indexPath.row];
    cell.contentView.backgroundColor = [UIColor clearColor];
    cell.backgroundColor = [UIColor clearColor];
    return cell;
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
